package com.dev.ac.web.server;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dev.ac.annotation.Login;
import com.dev.ac.common.Const;
import com.dev.ac.common.Result;
import com.dev.ac.entity.AAdmin;
import com.dev.ac.entity.ARole;
import com.dev.ac.service.AAdminService;
import com.dev.ac.service.ARoleService;
import com.dev.ac.service.AUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 付
 * @Date 2024-04-14 16:51
 * @Version 1.0
 * @description
 * @since 1.0
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

	@Autowired
	AAdminService aAdminService;
	@Autowired
	ARoleService aRoleService;

	@Login(issuer = Const.GRADE_ADMIN)
	@GetMapping("/list")
	public Result list() {
		List<AAdmin> list = aAdminService.list();
		for (AAdmin aAdmin : list) {
			ARole byId = aRoleService.getById(aAdmin.getRoleId());
			aAdmin.setARole(byId);
		}
		return Result.success(list);
	}

	@GetMapping("/disable")
	public Result disable(Integer id) {
		AAdmin byId = aAdminService.getById(id);
		Integer i = 0;
		if (byId.getIsDelete()==0){
			i=1;
		}
		aAdminService.update(new UpdateWrapper<AAdmin>()
				.eq("id", id)
				.set("is_delete", i)
		);

		return Result.success();
	}
}
